package cn.com.oceansoft.osc.ms.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 系统全局常量
 * @author ganlu
 * @create 2017-01-10 15:13
 * @email  ganlu@oceansoft.com.cn
 */
@Configuration
public class AppConstant {
    public static final long TOKEN_EXPIRE=600;    //注册短信过期时间

    public static final String WX_APPID="wxb1d572cf25b9a144";
    public static final String WX_SECRET="ea60c63316f9810cfaf1479642f34b92";
    public static final String WX_TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token";
    public static final String WX_TICKET_URL="https://api.weixin.qq.com/cgi-bin/ticket/getticket";

    public static final String TOKEN_KEY="1234567890123456";

    public static final String gaywurl="http://www.jxga.gov.cn/e/extend/api.php?mod=list";
    public static final String gaywDetailurl="http://www.jxga.gov.cn/e/extend/api.php?mod=view";
    public static final  String SIGN_PERFIX="YNGA";
    public  static  final  int SIGN_ERROR=181002;
    public static  final int DATA_NOTFOUND=181003;
    public static  final int DATA_SUCCESS=181001;
    public static final String SMS_REG_TEMPLATE="你的验证码为XXX,请在五分钟内验证。";  //注册短信模板
    public static final long SMS_REG_EXPIRE=300;    //注册短信过期时间
    public static final int ZERO = 0;
    public static final int SUCCES_CODE_USER = 212001;  //成功返回信息
    public static final int SUCCES_ZXXX = 200;
    public static final int ERR_USER_TELEPHONE_EMPTY = 211000;            //手机号不能为空
    public static final int ERR_CODE_USERORPWD_INVALID = 211001;          //账户或密码不正确
    public static final int ERR_CODE_USER_FROZEN = 211002;                //账户暂被锁定，请稍后再试
    public static final int ERR_CODE_USER_VERICODE_INVALID = 211003;      //验证码无效
    public static final int ERR_CODE_USER_DISABLED = 211004;              //账户被禁用
    public static final int ERR_CODE_PASSWORD_INVALID = 211005;           //密码不正确
    public static final int ERR_CODE_IDNUM_INVALID = 211006;              //身份证不正确
    public static final int ERR_CODE_IDNUM_EXISTS = 211066;              //身份证已存在
    public static final int ERR_CODE_ALLOW_CODE=211007;                   //账户或密码不正确,登录次数过多
    public static final int REG_ERR_PHONE_INVALID = 211010;               //注册手机号不正确
    public static final int REG_ERR_PWD_SIMPLE = 211011;                  //注册密码强度不够
    public static final int REG_ERR_PHONE_EXISTS = 211012;                //注册手机号已存在
    public static final int REG_ERR_SMSCODE_INVALID = 211013;             //短信验证码不正确
    public static final int REG_ERR_FAILUER = 211019;                     //人员注册失败
    public static final int REG_ERR_UPDATE_PWD = 211030;                  //修改密码失败
    public static final int REG_ERR_UPDATE_USER = 211031;                 //修改用户信息失败
    public static final int ERR_NAME_OR_ID_INVALID=211061;                //姓名或身份证或空

//-------------------------系统默认配置------------------------------------------
    private static final Logger logger = LoggerFactory.getLogger(AppConstant.class);
    /**
     * 最大文件上传限制
     */
    private static final long MAX_FILE_UPLOAD_SIZE =5242880;// 5 * 1024 * 1024;  //5M
    private static final String CONFIG_KEY_DES_PREFIX = "osc.config.des";
    private static final String CONFIG_KEY_AES_PREFIX = "osc.config.aes";
    private static final String CONFIG_KEY_FILE_UPLOAD_PREFIX = "osc.config.upload";
    private static AppConstant sAppConstant;
    /**
     * APP实名信息拉取接口
     */
    public  static final String APP_SM_URL="https://iauth-sandbox.wecity.qq.com/new/cgi-bin/getdetectinfo.php";

    public AppConstant() {
        sAppConstant = this;
    }
    /**
     * 文件上传配置
     */
    @ConfigurationProperties(prefix = CONFIG_KEY_FILE_UPLOAD_PREFIX)
    public static class UploadConfig {

        private long maxUploadSize = MAX_FILE_UPLOAD_SIZE;

        public long getMaxUploadSize() {
            return maxUploadSize;
        }

        public void setMaxUploadSize(long maxUploadSize) {
            this.maxUploadSize = maxUploadSize;
        }
    }

    /**
     * DES加密配置
     */
    @ConfigurationProperties(prefix = CONFIG_KEY_DES_PREFIX)
    public static class DesConfig {

        private String vector;
        private String secretKey;

        public String getVector() {
            return vector;
        }

        public void setVector(String vector) {
            this.vector = vector;
        }

        public String getSecretKey() {
            return secretKey;
        }

        public void setSecretKey(String secretKey) {
            this.secretKey = secretKey;
        }
    }

    /**
     * AES加密配置
     */
    @ConfigurationProperties(prefix = CONFIG_KEY_AES_PREFIX)
    public static class AesConfig {

        private String vector;
        private String secretKey;

        public String getVector() {
            return vector;
        }

        public void setVector(String vector) {
            this.vector = vector;
        }

        public String getSecretKey() {
            return secretKey;
        }

        public void setSecretKey(String secretKey) {
            this.secretKey = secretKey;
        }
    }

    public static AppConstant getInstance() {
        return sAppConstant;
    }

    @Bean
    public DesConfig desConfig() {
        return new DesConfig();
    }

    @Bean
    public UploadConfig uploadConfig() {
        return new UploadConfig();
    }

    @Bean
    public AesConfig aesConfig() {
        logger.debug("aesConfig");
        return new AesConfig();
    }

    public static DesConfig getDesConfig() {
        return sAppConstant.desConfig();
    }

    public static AesConfig getAesConfig() {
        return sAppConstant.aesConfig();
    }

    public static UploadConfig getUploadConfig() {
        return sAppConstant.uploadConfig();
    }


    //ems接口参数前缀
    public static final String CONFIG_KEY_ALIPAY_PREFIX="alipay";

    @Bean
    public AliPayConfig AliPayConfig() {
        return new AliPayConfig();
    }
    /**
     * ems 配置
     */
    @ConfigurationProperties(prefix = CONFIG_KEY_ALIPAY_PREFIX)
    public static class AliPayConfig {

        private  String myPrivateKey;
        private  String myPublicKey;
        private  String alipayPublicKey;
        private  String appid;

        public String getMyPrivateKey() {
            return myPrivateKey;
        }

        public void setMyPrivateKey(String myPrivateKey) {
            this.myPrivateKey = myPrivateKey;
        }

        public String getMyPublicKey() {
            return myPublicKey;
        }

        public void setMyPublicKey(String myPublicKey) {
            this.myPublicKey = myPublicKey;
        }

        public String getAlipayPublicKey() {
            return alipayPublicKey;
        }

        public void setAlipayPublicKey(String alipayPublicKey) {
            this.alipayPublicKey = alipayPublicKey;
        }

        public String getAppid() {
            return appid;
        }

        public void setAppid(String appid) {
            this.appid = appid;
        }
    }

    public static final String CONFIG_KEY_POLICE_PREFIX="police";

    @ConfigurationProperties(prefix = CONFIG_KEY_POLICE_PREFIX)
    public static class PoliceConfig{

        private String server;
        private String apiUrl;
        private String siteId;
        private String serverId;
        private String clientId;
        private String requestUrl;
        private String password;

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public String getRequestUrl() {
            return requestUrl;
        }

        public void setRequestUrl(String requestUrl) {
            this.requestUrl = requestUrl;
        }

        public String getServer() {
            return server;
        }

        public void setServer(String server) {
            this.server = server;
        }

        public String getApiUrl() {
            return apiUrl;
        }

        public void setApiUrl(String apiUrl) {
            this.apiUrl = apiUrl;
        }

        public String getSiteId() {
            return siteId;
        }

        public void setSiteId(String siteId) {
            this.siteId = siteId;
        }

        public String getServerId() {
            return serverId;
        }

        public void setServerId(String serverId) {
            this.serverId = serverId;
        }

        public String getClientId() {
            return clientId;
        }

        public void setClientId(String clientId) {
            this.clientId = clientId;
        }
    }

    public static final String CONFIG_KEY_TENCENT_USERCONFIRM="userconfirm";
    @ConfigurationProperties(prefix = CONFIG_KEY_TENCENT_USERCONFIRM)
    public static class UserConfirmConfig{

        private  String secretkey;
        private  String appid;
        private  String url;
        private  String appUrl;
        private  String expired;
        private String redirectUrl;
        private String infoUrl;
        private String aseKey;

        public String getAseKey() {
            return aseKey;
        }

        public void setAseKey(String aseKey) {
            this.aseKey = aseKey;
        }

        public String getInfoUrl() {
            return infoUrl;
        }

        public void setInfoUrl(String infoUrl) {
            this.infoUrl = infoUrl;
        }

        public String getRedirectUrl() {
            return redirectUrl;
        }

        public void setRedirectUrl(String redirectUrl) {
            this.redirectUrl = redirectUrl;
        }

        public String getExpired() {
            return expired;
        }

        public void setExpired(String expired) {
            this.expired = expired;
        }

        public String getSecretkey() {
            return secretkey;
        }

        public void setSecretkey(String secretkey) {
            this.secretkey = secretkey;
        }

        public String getAppid() {
            return appid;
        }

        public void setAppid(String appid) {
            this.appid = appid;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public String getAppUrl() {
            return appUrl;
        }

        public void setAppUrl(String appUrl) {
            this.appUrl = appUrl;
        }
    }


    @Bean
    public UserConfirmConfig secretkey(){return new UserConfirmConfig();}

    @Bean
    public PoliceConfig PoliceConfig(){return  new PoliceConfig();}



}
